#include"hashtable.h"

namespace ybc
{
	template<class K, class V, class Hash = hash<K>>
	class unordered_map
	{
		typedef pair<const K, V> T;
		
		struct MapKeyOfT
		{
			const K& operator () (const T& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename hashtable<K, T, MapKeyOfT, Hash>::iterator iterator;
		typedef typename hashtable<K, T, MapKeyOfT, Hash>::const_iterator const_iterator;
		
		iterator begin()
		{
			return _ht.begin();
		}

		iterator end()
		{
			return _ht.end();
		}

		const_iterator cbegin()
		{
			return _ht.cbegin();
		}

		const_iterator cend()
		{
			return _ht.cend();
		}

		pair<iterator, bool> insert(const T& kv)
		{
			return _ht.insert(kv);
		}

		iterator find(const K& key)
		{
			return _ht.find(key);
		}

		bool erase(const K& key)
		{
			return _ht.erase(key);
		}

		V& operator [] (const K& key)
		{
			pair<iterator, bool> ret = insert(make_pair(key, V()));
			return ret.first->second;
		}
	private:
		hashtable<K, T, MapKeyOfT, Hash> _ht;
	};
}